package org.ruixue.controller;
import cn.rkylin.oms.common.dto.DBLog;
import com.alibaba.fastjson.JSON;
import org.ruixue.response.BaseResponse;
import org.ruixue.service.RefundService;
import org.ruixue.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
@RequestMapping("/refund")
public class RefundController {
	
    @Autowired
    RefundService refundService;

    @Autowired
    LogUtil logUtil;

    /**
     * http://localhost:40005/microservice-yiyouyayin/refund/downloadYiRefundWhole
     * 获取全部退款单信息
     * 
     * @param shopId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/downloadYiRefundWhole", method = RequestMethod.GET)
    private ResponseEntity<BaseResponse> downloadYiRefundWhole() {
        BaseResponse response = new BaseResponse();
        try {
            response = refundService.downloadYiRefundWhole();
            logUtil.info(new DBLog("", "", "downloadYiRefundWhole", JSON.toJSONString(response)));
        } catch (Exception e) {
            e.printStackTrace();
            response.setMsg(e.getMessage());
            response.setSuccess("false");
            logUtil.error(new DBLog("", "", "downloadYiRefundWhole", e.getMessage()), e);
        }
        return new ResponseEntity<BaseResponse>(response, HttpStatus.OK);
    }
    
    /**
     * http://localhost:40005/microservice-yiyouyayin/refund/downloadYiRefund?shopId=55ed507f052747a0aa97d56d63f53f99
     * 根据网店获取退款单信息
     * 
     * @param shopId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/downloadYiRefund", method = RequestMethod.GET)
    private ResponseEntity<BaseResponse> downloadYiRefund(@RequestParam String shopId) {
        BaseResponse response = new BaseResponse();
        try {
            response = refundService.downloadYiRefund(shopId);
            logUtil.info(new DBLog(shopId, "", "downloadYiRefund", JSON.toJSONString(response)));
        } catch (Exception e) {
            e.printStackTrace();
            response.setMsg(e.getMessage());
            response.setSuccess("false");
            logUtil.error(new DBLog(shopId, "", "downloadYiRefund", e.getMessage()), e);
        }
        return new ResponseEntity<BaseResponse>(response, HttpStatus.OK);
    }
}
